InformIT - Your Online Guide to Tech Reference

Log OutShopping CartView Cart

HomeArticlesBook StoreOnline BooksAuthorsMyInformIT
Home > Articles > Web Development > More Topics... > .NET >

Save

 

Discuss

   

E-mail

Working With ADO.NET Transactions
OCT 25, 2002 By Jason Lefebvre. Article is provided courtesy of Sams.

Contents
1Hour 18: Working with Transactions
2Transactions and ADO.NET
3Transactions with Stored Procedures
4Summary
5Q&A
6Workshop
See Also

This sample chapter is from Sams Teach Yourself ADO.NET in 24 Hours.

Also By This Author
Using the ADO.NET's Built-In ASP.NET List Controls
Binding Data to List Controls with ADO.NET
Using ADO.NET's DataReader and DataAdapter
more…
Related Articles
Connected Operations in ADO.NET
Binding Data to List Controls with ADO.NET
Disconnected Operations Part I: DataSet and DataAdapter
more…
Related Books
Visual Basic® .NET Developer's Guide to ASP .NET, XML and ADO.NET
Database Programming with Visual Basic .NET and ADO.NET: Tips, Tutorials, and Code
more…

 

Almost any relational database system provides the facility for database transactions. Database transactions are a set of commands that either all fail or all succeed, as a group. ADO.NET provides a set of objects used to create and work with transactions, which will be discussed in this lesson.

Other articles by Jason Lefebvre.

See all Sams Teach Yourself on InformIT Programming Tutorials.

Advertise With Us

In the preceding hour, you saw how to use SQL and OLE DB connection pooling in your applications to increase your application's responsiveness and decrease the amount of system resources used. In this hour, you're going to see how database transactions can help maintain the integrity of your database. A transaction is a set of actions that are executed as a group, with all actions succeeding or all actions failing.

In this hour, you'll see how to

  • Initiate a database transaction using ADO.NET

  • Roll back changes made to a database

  • Save changes made while using a transaction

  • Perform a database transaction in a stored procedure

What Is a Transaction?

Consider this classic transaction example: A bank needs to transfer a million dollars from bank account A to bank account B. First, the money in A needs to be placed in B. Then, after the transfer has been verified, the money needs to be removed from account A. Obviously, if there is any sort of problem placing the money in account B, you do not want to remove it from account A. Likewise, if the money is placed successfully in account B, you want to ensure that it is removed from account A. All actions need to fail or all actions need to succeed.

If you were coding an application to perform the monetary transactions in the last paragraph, you could do so relatively easily without having to use a transaction by intelligently trapping application errors and maintaining state. However, consider that a transaction isn't limited in size. Imagine keeping track of 500 database changes manually! Also, suppose the server is turned off in the middle of your application's processing. You need to make sure that when the application is brought back online, it knows exactly where it stopped so that it can either reverse all the changes made or attempt to continue where it left off.

Fortunately, because transactions exist, you need not worry about any of these problems. By wrapping your database actions in a transaction, you can help ensure that your data remains correct and consistent. In the next few sections, you'll see how to use database transactions.


   
Next Section
2. Transactions and ADO.NET
Rate This Article
 
How would you rate this article?    

Most Active Comments
 
CommentAuthorRepliesPosted

 Spanning a TRX in varios method calls (may be connections)

peix

0OCT 29, 2002 07:07:04 AM
See All Comments 
 
Make a New Comment

Subject:

Username:


    Change Username

Message: